package pl.vanta.mjuzik.gui.tables;

import java.awt.Color;

import pl.vanta.mjuzik.model.AudioFile;
import pl.vanta.mjuzik.services.ConfigurationService;
import pl.vanta.utils.gui.tables.ColumnDescription;
import pl.vanta.utils.gui.tables.VTableModel;
import pl.vanta.utils.gui.tables.renderers.MinMaxColorRenderer;
import pl.vanta.utils.gui.tables.renderers.NumberRenderer;
import pl.vanta.utils.gui.tables.renderers.SizeRenderer;
import pl.vanta.utils.gui.tables.renderers.SizeRendererParam;

public class PlaylistTableModel extends VTableModel<AudioFile>
{
	private static final long	serialVersionUID	= -6612139332072801876L;

	final ConfigurationService	configurationService;

	public PlaylistTableModel(ConfigurationService configurationService)
	{
		this.configurationService = configurationService;

		setIndexColumnDescription(new ColumnDescription("L.p.", null, false, 50));

		this.columnsDescriptions = new ColumnDescription[6];

		this.columnsDescriptions[0] = new ColumnDescription("Nazwa", String.class, true, 50);
		this.columnsDescriptions[1] = new ColumnDescription("Katalog", String.class, true, 50);
		this.columnsDescriptions[2] = new ColumnDescription("Typ", String.class, false, 50);
		this.columnsDescriptions[3] = new ColumnDescription("Czas", Integer.class, false, 50, true, new NumberRenderer(
				this.configurationService.getOptions().getTimeFormat()));
		this.columnsDescriptions[4] = new ColumnDescription("Rozmiar", Integer.class, false, 75, true,
				new SizeRenderer(SizeRendererParam.MB, "0.0"));
		this.columnsDescriptions[5] = new ColumnDescription("Ranking", Integer.class, false, 50, true,
				new MinMaxColorRenderer(Color.RED, Color.GREEN));
	}

	@Override
	public Object getValue(AudioFile entity, int column)
	{
		switch (column)
		{
			case 0:
				return entity.getFile().getName();
			case 1:
				return entity.getFile().getParent();
			case 2:
				return entity.getFileInfo() == null ? "" : entity.getFileInfo().getType().getExtension();
			case 3:
				return entity.getFileInfo() == null ? 0 : entity.getFileInfo().getPlayTime();
			case 4:
				return entity.getFile().length();
			case 5:
				return entity.getRating();
			default:
				return null;
		}
	}
}